//package com.levi.mqtt;
//
//import org.eclipse.paho.client.mqttv3.MqttClient;
//import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
//import org.eclipse.paho.client.mqttv3.MqttException;
//import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.stereotype.Component;
//
///**
// * @author shentong
// * @since 2022/9/12 21:57
// */
//@Component
//@Configuration
//public class MqttConfig {
//
//	@Autowired
//	private MqttProperties mqttProperties;
//
//    @Bean
//    public MqttClient mqttClient() throws MqttException {
//        MqttClient client = new MqttClient(mqttProperties.getBroker(),
//                mqttProperties.getClientId(),new MemoryPersistence());
//        //MQTT  连接选项
//        MqttConnectOptions connectOps = new MqttConnectOptions();
//        connectOps.setUserName(mqttProperties.getUsername());
//        connectOps.setPassword(mqttProperties.getPassword().toCharArray());
//        //保留会话
//        connectOps.setCleanSession(true);
//        //设置回调
////        client.setCallback(new OnMessageCallback());
//        // 建立连接
//        System.out.println("Connecting to broker: " + mqttProperties.getBroker());
//        client.connect(connectOps);
//        // 订阅
//        client.subscribe(mqttProperties.getSubTops());
//        return client;
//	}
//}
